<template>
  <com-card>
    <div slot="com_title" class="title_con">修改密码</div>

    <div slot="com_content">
      <el-form size="small" label-width="100px" :model="ruleForm">
        <el-form-item label="当前密码：" prop="oldPwd">
          <el-input v-model="ruleForm.oldPwd"></el-input>
        </el-form-item>

        <el-form-item label="新密码：" prop="newPwd">
          <el-input v-model="ruleForm.newPwd"></el-input>
        </el-form-item>

        <el-form-item label="确认密码" prop="rePwd">
          <el-input v-model="ruleForm.rePwd"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="gofn">提交</el-button>
          <el-button>重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </com-card>
</template>

<script>
import { aqi_checkoldpwd, aqi_editpwd } from "../../api/users";
import ComCard from "../../components/comcard/index.vue";
export default {
  components: {
    ComCard,
  },
  data() {
    return {
      ruleForm: {
        oldPwd: "",
        newPwd: "",
        rePwd: "",
      },
    };
  },
  methods: {
    async gofn() {
      const { code, msg } = await aqi_checkoldpwd({ oldPwd:this.ruleForm.oldPwd });
      if (code == 0) {
        if (this.ruleForm.newPwd == this.ruleForm.rePwd) {
          const { code, msg } = await aqi_editpwd({ newPwd:this.ruleForm.newPwd });
          if (code == 0) {
            this.$message.success(msg);
          } else {
            this.$message.error(msg);
          }
        } else {
          this.$message("确认密码与新密码不一致");
        }
      } else {
        this.$message.error(msg);
      }
    },
  },
};
</script>

<style lang="less" scoped>
.title_con {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style>